﻿// Genius
// Copyright (C) 2016 Dirk Friedenberger, www.frittenburger.de
//   
// This source file is subject to the Microsoft Public License (Ms-PL).
// http://www.opensource.org/licenses/ms-pl.html
// All other rights reserved.
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Installer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Genius.Locator.Internal
{
    public class ContainerHolder
    {
        private static WindsorContainer _container = null;
        private static WindsorContainer Container
        {
            get
            {
                if (_container == null)
                {
                    _container = new WindsorContainer();
                    _container.Install(Configuration.FromAppConfig());
                }
                return _container;
            }
        }

        public static void Reset()
        {
            _container = null;
        }


        public static void Register<T1>(T1 instance) where T1 : class
        {
            Container.Register(Component.For<T1>().Instance(instance).IsDefault());
        }

        public static T Resolve<T>() where T : class
        {
            return Container.Resolve<T>();
        }
        public static T Resolve<T>(object arg) where T : class
        {
            return Container.Resolve<T>(arg);
        }
        public static T Resolve<T>(string name) where T : class
        {
            return Container.Resolve<T>(name);
        }
    }
}
